<?php
class regMod extends commonMod{

	// 注册协议
	public function index(){

		$arr = __query("select * from {tabpre}about where classid=996 and `show`=1 and recover=0 ");
		$this->assign("det", $arr[0]['content']);

		$this->display('reg_index');
	}

	// 注册表单
	public function redfrom(){

		$this->display('reg_from_index');
	}

	// 注册提交
	public function reg_post(){

		if ($_POST) {

			$username = __safe('username');
			$password = __safe('password');
			$password2 = __safe('password2');
			$name = __safe('name');
			$sex = __safe('sex');
			$zhiwu = __safe('zhiwu');
			$email = __safe('email');
			$tel = __safe('tel');
			$phone = __safe('phone');
			$vcode = __safe('vcode');

			// 验证码是否有误
			if ($_SESSION['lebang_vcode'] != $vcode or $vcode=='') {
				echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
				echo '<script>alert(\'验证码有误\');history.go(-1);</script>';
				exit;
			}

			// 两次密码输入是否有误
			if ($password != $password2) {
				echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
				echo '<script>alert(\'两次密码输入不一至\');history.go(-1);</script>';
				exit;
			}

			// 数据是否为空
			if (empty($username) or empty($password) or empty($name) or empty($sex) or empty($zhiwu) or empty($email) or empty($tel) or empty($phone)) {
				echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
				echo '<script>alert(\'带*号的为必填项，请认真填写\');history.go(-1);</script>';
				exit;
			}

			@__query("INSERT INTO {tabpre}member (`title`, `password`, `name`, `sex`, `zhiwu`, `email`, `tel`, `phone`, `datetime`, `show`, `recover`) VALUES 
				('$username', '$password', '$name', '$sex', '$zhiwu', '$email', '$tel', '$phone', '".date('Y-m-d h:i:s')."', 0, 0) ");

			echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
			echo '<script>alert(\'注册成功\');history.go(-1);</script>';
			exit;

		}
	}
}